package fr.laposte.erreurcaisse.controlers;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import oracle.jdbc.pool.OracleDataSource;

public class DataSourceHelper
{
	private static DataSourceHelper	instance	= null;
	private Connection	            c	       = null;
	
	private DataSourceHelper() throws FileNotFoundException, IOException,
	    SQLException
	{
		PropertiesManager p = PropertiesManager.getInstance();
		System.out.println("connecté");
		OracleDataSource ds = new OracleDataSource();
		ds.setURL(p.getPrefix() + p.getHost() + p.getPort() + ":xe");
		ds.setUser(p.getUser());
		ds.setPassword(p.getPass());
		c = ds.getConnection();
	}
	
	public static DataSourceHelper getInstance() throws FileNotFoundException,
	    IOException, SQLException
	{
		if (instance == null)
			instance = new DataSourceHelper();
		return instance;
	}
	
	public Connection getConnection()
	{
		return c;
	}
	
}
